======For Application Developers======

Here is some info that anyone wanting to modify Pedal Box / Pedal Board might find useful. \\ 
This will expand as I get the energy to do some typing.

Application Development and Electronics are hardly my field of expertise. I'm learning mostly as I go along. \\ You'll see some pretty poor examples of coding, and some of it is hard to follow. You'll get used to it! :)




=====Memory=====
Pedal Box / Pedal Board uses a 24LC256 chip to store device information and settings. \\ 
The PIC's Internal EEPROM is also used. \\ 

===Internal EEPROM===
**Device to control table**

^ Fixed Buttons                                     ^^^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx      ||| 16          |0x00 |
|            ^Description     ^Data                   ^size (bytes) ^       |
|            |Bankstick #     |0 - 7                  | 1           |       |
|            |                ^16 entries             ^1  bytes per entry  ^^ \\ 

^ Banked Buttons                                    ^^^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx      ||| 128         |0x10 |
|            ^Description     ^Data                   ^size (bytes) ^       |
|            |Bankstick #     |0 - 7                  | 1           |       |
|            |                ^128 entries            ^1  bytes per entry  ^^ \\ 

^ Expression Pedals / AIN                           ^^^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx      ||| 8           |0x90 |
|            ^Description     ^Data                   ^size (bytes) ^       |
|            |Bankstick #     |0 - 7                  | 1           |       |
|            |                ^8  entries             ^1  bytes per entry  ^^ \\ 

===Bankstick===
**Device Information** \\ 
^ Event Map                                         ^^^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx      ||| 5120        |0x0000 |
|            ^Description     ^Data                   ^size (bytes) ^offset |
|            |Name            |16x ASCII characters   | 16          |+0x00  |
|            |Status          |0x80, 0x90, 0xb0, 0xc0 | 1           |+0x10  |
|            |Param 1         |0x00 - 0x7f            | 1           |+0x11  |
|            |Event Handler   |0 - 14                 | 1           |+0x12  |
|            |Current Value   |0 - 127                | 1           |+0x13  |
|            |                ^256 Entries            ^20 bytes per entry  ^^ \\ 

<sub>Value maps do not need all 128 enties. The application needs to now how many there really is</sub> \\ 
^Description                  |^Data                ^Total Bytes  ^Address|
| Entries in Value Map 1      ||1 - 128             | 1           |0x1400 |
| Reserved                    ||                    | 1           |0x1401 |
^ Value Map 1                 ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 2304        |0x1402 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Name            |16x ASCII Characters | 16          |+0x00  |
|            |Value           |0x00 - 0x7f          | 1           |+0x10  |
|            |Reserved        |                     | 1           |+0x11  |
|            |                ^128 Entries          ^18 bytes per entry  ^^

^Description                  |^Data                ^Total Bytes  ^Address|
| Entries in Value Map 2      ||1 - 128             | 1           |0x1d02 |
| Reserved                    ||                    | 1           |0x1d03 |
^ Value Map 2                 ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 2304        |0x1d04 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Name            |16x ASCII Characters | 16          |+0x00  |
|            |Value           |0x00 - 0x7f          | 1           |+0x10  |
|            |Reserved        |                     | 1           |+0x11  |
|            |                ^128 Entries          ^18 bytes per entry  ^^

^Description                  |^Data                ^Total Bytes  ^Address|
| Entries in Value Map 3      ||1 - 128             | 1           |0x2604 |
| Reserved                    ||                    | 1           |0x2605 |
^ Value Map 3                 ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 2304        |0x2606 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Name            |16x ASCII Characters | 16          |+0x00  |
|            |Value           |0x00 - 0x7f          | 1           |+0x10  |
|            |Reserved        |                     | 1           |+0x11  |
|            |                ^128 Entries          ^18 bytes per entry  ^^

^Description                  |^Data                ^Total Bytes  ^Address|
| Entries in Value Map 4      ||1 - 128             | 1           |0x2f06 |
| Reserved                    ||                    | 1           |0x2f07 |
^ Value Map 4                 ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 2304        |0x2f08 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Name            |16x ASCII Characters | 16          |+0x00  |
|            |Value           |0x00 - 0x7f          | 1           |+0x10  |
|            |Reserved        |                     | 1           |+0x11  |
|            |                ^128 Entries          ^18 bytes per entry  ^^

^Description                  |^Data                ^Total Bytes  ^Address|
| Entries in Value Map 5      ||1 - 128             | 1           |0x3808 |
| Reserved                    ||                    | 1           |0x3809 |
^ Value Map 5                 ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 2304        |0x380a |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Name            |16x ASCII Characters | 16          |+0x00  |
|            |Value           |0x00 - 0x7f          | 1           |+0x10  |
|            |Reserved        |                     | 1           |+0x11  |
|            |                ^128 Entries          ^18 bytes per entry  ^^

^Description                  |^Data                ^Total Bytes  ^Address|
| Entries in Value Map 6      ||1 - 128             | 1           |0x410a |
| Reserved                    ||                    | 1           |0x410b |
^ Value Map 6                 ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 2304        |0x410c |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Name            |16x ASCII Characters | 16          |+0x00  |
|            |Value           |0x00 - 0x7f          | 1           |+0x10  |
|            |Reserved        |                     | 1           |+0x11  |
|            |                ^128 Entries          ^18 bytes per entry  ^^

^Description                  |^Data                ^Total Bytes  ^Address|
| Entries in Value Map 7      ||1 - 128             | 1           |0x4a0c |
| Reserved                    ||                    | 1           |0x4a0d |
^ Value Map 7                 ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 2304        |0x4a0c |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Name            |16x ASCII Characters | 16          |+0x00  |
|            |Value           |0x00 - 0x7f          | 1           |+0x10  |
|            |Reserved        |                     | 1           |+0x11  |
|            |                ^128 Entries          ^18 bytes per entry  ^^


^Description                  |^Data                ^Total Bytes  ^Address|
| Entries in Value Map 8      ||1 - 128             | 1           |0x530e |
| Reserved                    ||                    | 1           |0x530f |
^ Value Map 8                 ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 2304        |0x5310 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Name            |16x ASCII Characters | 16          |+0x00  |
|            |Value           |0x00 - 0x7f          | 1           |+0x10  |
|            |Reserved        |                     | 1           |+0x11  |
|            |                ^128 Entries          ^18 bytes per entry  ^^

^Description                  |^Data                ^Total Bytes  ^Address|
| Entries in Value Map 9      ||1 - 128             | 1           |0x5c10 |
| Reserved                    ||                    | 1           |0x5c11 |
^ Value Map 9                 ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 2304        |0x5c12 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Name            |16x ASCII Characters | 16          |+0x00  |
|            |Value           |0x00 - 0x7f          | 1           |+0x10  |
|            |Reserved        |                     | 1           |+0x11  |
|            |                ^128 Entries          ^18 bytes per entry  ^^



**Settings** \\ 
^ DIN Map                     ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 576         |0x6520 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Entry #         |0x00 - 0xff          | 1           |+0x00  |
|            |Low value       |0x00 - 0x7e          | 1           |+0x01  |
|            |High value      |0x01 - 0x7f          | 1           |+0x02  |
|            |Button Type     |0, 1                 | 1           |+0x03  |
|            |                ^144 Entries          ^4 bytes per entry   ^^


^ Device Info                                       ^^^Total Bytes  ^Address|
|            ^Description     ^Data                   ^size (bytes) ^offset |
|            |Name            |16x ASCII characters   | 16          |0x6800 - 0x680f  |
|            |Channel         |0 - 15                 | 1           |0x6ffe |
|            |Reserved        |                       | 1           |0x6fff |
|            |                ^                       ^                    ^^ \\ 


^ AIN Fixed Settings          ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 8           |0x6900 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Pedal 1         |0, 1                 | 1           |+0x00  |
|            |Pedal 2         |0, 1                 | 1           |+0x01  |
|            |Pedal 3         |0, 1                 | 1           |+0x02  |
|            |Pedal 4         |0, 1                 | 1           |+0x03  |
|            |Pedal 5         |0, 1                 | 1           |+0x04  |
|            |Pedal 6         |0, 1                 | 1           |+0x05  |
|            |Pedal 7         |0, 1                 | 1           |+0x06  |
|            |Pedal 8         |0, 1                 | 1           |+0x07  |
|            |                ^                     ^                    ^^

^ AIN Map 1                   ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 512         |0x7000 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Entry #         |0x00 - 0xff          | 1           |+0x00  |
|            |Low value       |0x00 - 0x7e          | 1           |+0x01  |
|            |High value      |0x01 - 0x7f          | 1           |+0x02  |
|            |Reserved        |                     | 1           |+0x03  |
|            |                ^128 Entries          ^4 bytes per entry   ^^

^ AIN Map 2                   ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 512         |0x7200 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Entry #         |0x00 - 0xff          | 1           |+0x00  |
|            |Low value       |0x00 - 0x7e          | 1           |+0x01  |
|            |High value      |0x01 - 0x7f          | 1           |+0x02  |
|            |Reserved        |                     | 1           |+0x03  |
|            |                ^128 Entries          ^4 bytes per entry   ^^

^ AIN Map 3                   ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 512         |0x7400 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Entry #         |0x00 - 0xff          | 1           |+0x00  |
|            |Low value       |0x00 - 0x7e          | 1           |+0x01  |
|            |High value      |0x01 - 0x7f          | 1           |+0x02  |
|            |Reserved        |                     | 1           |+0x03  |
|            |                ^128 Entries          ^4 bytes per entry   ^^

^ AIN Map 4                   ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 512         |0x7600 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Entry #         |0x00 - 0xff          | 1           |+0x00  |
|            |Low value       |0x00 - 0x7e          | 1           |+0x01  |
|            |High value      |0x01 - 0x7f          | 1           |+0x02  |
|            |Reserved        |                     | 1           |+0x03  |
|            |                ^128 Entries          ^4 bytes per entry   ^^

^ AIN Map 5                   ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 512         |0x7800 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Entry #         |0x00 - 0xff          | 1           |+0x00  |
|            |Low value       |0x00 - 0x7e          | 1           |+0x01  |
|            |High value      |0x01 - 0x7f          | 1           |+0x02  |
|            |Reserved        |                     | 1           |+0x03  |
|            |                ^128 Entries          ^4 bytes per entry   ^^

^ AIN Map 6                   ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 512         |0x7a00 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Entry #         |0x00 - 0xff          | 1           |+0x00  |
|            |Low value       |0x00 - 0x7e          | 1           |+0x01  |
|            |High value      |0x01 - 0x7f          | 1           |+0x02  |
|            |Reserved        |                     | 1           |+0x03  |
|            |                ^128 Entries          ^4 bytes per entry   ^^

^ AIN Map 7                   ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 512         |0x7c00 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Entry #         |0x00 - 0xff          | 1           |+0x00  |
|            |Low value       |0x00 - 0x7e          | 1           |+0x01  |
|            |High value      |0x01 - 0x7f          | 1           |+0x02  |
|            |Reserved        |                     | 1           |+0x03  |
|            |                ^128 Entries          ^4 bytes per entry   ^^

^ AIN Map 8                   ^^                    ^Total Bytes  ^Address|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    ||| 512         |0x7e00 |
|            ^Description     ^Data                 ^size (bytes) ^offset |
|            |Entry #         |0x00 - 0xff          | 1           |+0x00  |
|            |Low value       |0x00 - 0x7e          | 1           |+0x01  |
|            |High value      |0x01 - 0x7f          | 1           |+0x02  |
|            |Reserved        |                     | 1           |+0x03  |
|            |                ^128 Entries          ^4 bytes per entry   ^^

===A Simple Example===
This will print the Status byte of entry 32 in the event map\\ 
<code c>
entry = 32;
MIOS_LCD_CursorSet(0x00);
MIOS_LCD_PrintHex2(MIOS_BANKSTICK_Read(0x0000 + (entry * 20) + 0x10);
</code> \\ 
MIOS_LCD_PrintHex2( Bankstick read address (entry * bytes per entry) + offset of status byte )

===A Complex Example===
This example is part of AIN_NotifyChange.

It uses the pin moved and current program change number to recall the AIN settings \\ 
pin_mapped is the saved entry number of the event map \\ 
low and high value are used for scaling.

In this example, we first need to find which AIN map to use ( with pin * 0x200 )

<code c>
AIN_map_offset = pin * 0x200
pin_mapped = MIOS_BANKSTICK_Read(0x7000 + (AIN_map_offset) + (last_programchange_evnt1 * 4) + 0);
low_value  = MIOS_BANKSTICK_Read(0x7000 + (AIN_map_offset) + (last_programchange_evnt1 * 4) + 1);
high_value = MIOS_BANKSTICK_Read(0x7000 + (AIN_map_offset) + (last_programchange_evnt1 * 4) + 2);
</code>
variable  = Read Bankstick addr. 0x7#00 [depending on pin#] + (current program change number * bytes per entry) + offset



=====Basic MIDI Handling=====
Pedal Box / Pedal Board will only send or respond to midi events in the event map.

The found_event variables are used to store data from the banskstick relevant to the current midi event.

found_event.entry = entry number of the relevant event in the event map\\ 
found_event.name = name of the event\\ 
found_event.status = status byte\\ 
found_event.param1 = parameter 1 byte\\ 
found_event.event_handler = definition of how to handle the event\\ 

====Midi Input====
On recieving a complete MIDI event, event is first compared to the previous complete midi event (comparing status and param1 only). If they differ, the event map in the bankstick is scanned for a matching event. First checking the status byte only, if a match is found, the param1 byte is checked (this saves on bankstick read time). \\ 
If a match is found, the found_event variables are filled with the relevant data.

If the midi event matches the previous midi event, found_event is left as it was. This also saves bankstick read time.

Any special handling is performed (based on .event_handler), such as tap tempo, or modifing led indicator status. And the display handler is called to display the relevant data on the screen, again this is dependant on found_event.param2_def


====Expession Pedals====
When a pedal is moved, first Pedal Box / Pedal Board needs to know which settings to use. Each AIN has it's own settings map of 128 entries (1 for each program change).
The first AIN map is starts on bankstick at 0x7000, Each map is 512 bytes long, so we use <code c>MIOS_BANKSTICK_Read(0x7000 + (pin * 0x200))</code> to get the first entry of each map. \\
If AIN fixed for that pedal is set to 1, then the first entry is all we need as program changes are not taken into account.

Next we consider the current program change param1 byte. This is stored in variable 'last_programchange_evnt1'. \\ 
As there is 4 bytes in each entry. Add (last_programchange_evnt1 * 4) to the address code to get the relevant entry.

<code c>MIOS_BANKSTICK_Read(0x7000 + (pin * 0x200) + (last_programchange_evnt1 * 4))</code> 

Now that we have the right line. We need to extract the info, by adding the offset.
<code c>
pin_mappped= MIOS_BANKSTICK_Read(0x7000 + (pin * 0x200) + (last_programchange_evnt1 * 4) + 0)
low_value  = MIOS_BANKSTICK_Read(0x7000 + (pin * 0x200) + (last_programchange_evnt1 * 4) + 1)
high_value = MIOS_BANKSTICK_Read(0x7000 + (pin * 0x200) + (last_programchange_evnt1 * 4) + 2)
</code> 
pin_mapped stores the relevant event map entry number. \\ 
low_value stores the low value for scaling \\ 
high_value stores the high value for scaling \\ 

Now we use pin_mapped to fill the found_event variables.
Parameter 2 is scaled between the low and high value and placed in found_event.param2.

found_event.status .param1 .param2 are sent to MIDI TX handler.
the display is called, and the found_event variables are used to display infomation in the screen.

====Buttons====
FIXME